home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- #
- # TV-Man.Init.c
- #
- # Copyright © Apple Computer, Inc. 1989-1990
- # All rights reserved.
- #
- #
- # These are the all the functions that are necessary to initalize
- # the application. After these are used they will never be used again.
- # Therefore this segment will be unloaded at the end of its usefullness.
- #
- # In order to have an evironment which predictable events happen several definitions
- # must be established. The most critical is in the file architecture. Each functional
- # block will have its own source and header file. The main project file, in this
- # case TV-Man, will have its header file included with all other files. This will
- # allow for global constants. The utility source file shall contain functions that
- # are general purpose in nature and that can be used by all other functions. These
- # are intended not to be application or major block specific. In order for this to be
- # accomodated all functions in the utility source file must use only the information
- # that is passed to them or information that can be gleaned from the system via
- # toolbox calls. There will be no header file associated with the utility file as this
- # will destroy the intent of the utilities.
- #
- # There are several files which contain information which is global in nature .These
- # file are included in the main project header file. They are: x.Errors.h, x.Ext.h,
- # x.Protos.h, x.Menus.h. The reason for containing them in seperate files is one of
- # convienience and accesability.
- #
- #
- # Revision Log:
- #
- # 4-26-91 RGK Creation
- #
- #
- ------------------------------------------------------------------------------*/
-
-
- /* This is the list of "local" include files */
-
- #include "TV-Man.h"
- #include "TV-Man.Video.h"
- #include "TV-Man.Sound.h"
-
-
-
- #pragma segment Initialize /* set this files code segment */
-
-
-
- /* Set up the whole world, including global variables, Toolbox managers,
- and menus. Also create the one application window at this time. Because
- TV-Man has only one window and it is only disposed when the application
- quits, we will allocate its space here, before anything that might be a locked
- relocatable object gets into the heap. This way, we can force the storage to be
- in the lowest memory available in the heap. Window storage can differ widely
- amongst applications depending on how many windows are created and disposed. */
-
- void Initialize()
- {
- Handle menuBar;
- WindowPtr window;
- long total, contig;
- EventRecord event;
- short count;
- Rect maxrect;
- short wtop, wleft, wright, wbottom;
-
- gInBackground = false;
-
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
-
-
- /* This next bit of code is necessary to allow the default button of our
- alert be outlined. Call EventAvail so that we don't lose some important
- events. */
-
- for (count = 1; count <= 3; count++)
- EventAvail(everyEvent, &event);
-
-
-
-
- /* Ignore the error returned from SysEnvirons; even if an error occurred,
- the SysEnvirons glue will fill in the SysEnvRec. You can save a redundant
- call to SysEnvirons by calling it after initializing AppleTalk. */
-
- SysEnvirons(kSysEnvironsVersion, &gMac);
-
-
-
-
- /* Make sure that the machine has at least 128K ROMs. If it doesn't, exit. */
-
- if (gMac.machineType < 0) Error(eMajor, eMajorRoms);
-
-
-
- /* Move TrapAvailable call to after SysEnvirons so that we can tell
- in TrapAvailable if a tool trap value is out of range. */
-
- gHasWaitNextEvent = TrapAvailable(_WaitNextEvent, ToolTrap);
-
-
-
- /* Check the size of the application heap against a value that has been determined is
- the smallest heap this application can reasonably work in. This number should be
- derived by examining the size of the heap that is actually provided by MultiFinder
- when the minimum size requested is used. The derivation of the minimum size requested
- from MultiFinder is described in TV-Man.h. The check should be made because the
- preferred size can end up being set smaller than the minimum size by the user.
- This extra check acts to insure that your TV-Man is starting from a solid
- memory foundation. */
-
- if ((long) GetApplLimit() - (long) ApplicZone() < kMinHeap) Error(eMajor, eMajorHeap);
-
- /* Now, make sure that enough memory is free for your TV-Man to run. To check
- for this, call PurgeSpace and compare the result with a value that you have
- determined is the minimum amount of free memory TV-Man needs at initialization. */
-
- PurgeSpace(&total, &contig);
- if (total < kMinSpace) Error(eMajor, eMajorRam); /* error if to little RAM */
-
-
- /* make as large a window as the target maching can handle */
-
- window = (WindowPtr) NewPtr(sizeof(WindowRecord));
- if ((window == nil) || (ResError() != noErr)) /* check for a resource error */
- Error(eMajor, eMajorWindow); /* display major error alert box
- and dont come back */
-
-
- /* make a rectangle as large as possible but leave up the menu bar. The extra calculations
- in the SetRect are an effort to create a window with an even width and height. The variable
- setting of the wXXXX stuff is just for readability. Often I will burn the variable area
- in favor of using it instead of a compound (ie. looong) statement. */
-
- wtop = qd.screenBits.bounds.top;
- wleft = qd.screenBits.bounds.left;
- wright = qd.screenBits.bounds.right;
- wbottom = qd.screenBits.bounds.bottom;
-
- SetRect(&maxrect, wleft, wtop + 20,
- ((((wright - wleft) +1) /2) *2) +wleft, /* set up the right side */
- ((((wbottom - wtop) +1) /2) *2) +wtop); /* set up the left side */
-
-
- /* Now make our only window out of the rectangle */
-
- window = NewCWindow( (Ptr)window, &maxrect,"TV-Man",
- true, 2,(WindowPtr) -1, false, nil);
-
-
-
- /* set up the menus */
-
- menuBar = GetNewMBar(rMenu); /* read menus into menu bar */
- if ((menuBar == nil) || (ResError() != noErr)) /* check for a resource error */
- Error(eMajor, eMajorMenu); /* display major error alert box
- and dont come back */
- SetMenuBar(menuBar); /* install menus */
- DisposHandle(menuBar);
- AddResMenu(GetMHandle(mApple), 'DRVR'); /* add DA names to Apple menu */
- DrawMenuBar();
-
- gVideoPattern = iTestPattern; /* initalize the video parameters */
- } /*Initialize*/
-
-
-